<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../node_modules/axios/dist/axios.js"></script>
</head>
<body>
<button>发送请求</button>
<button>取消请求</button>
</body>
<script>
    const btns = document.querySelectorAll("button");
    let cancelFn = null;
    btns[0].onclick = function () {
        if(cancelFn)
            cancelFn();
        axios.get("http://zhangpeiyue.com/scoreList",{
            cancelToken:new axios.CancelToken(function(fn){
                cancelFn = fn;
            }),
            timeout:2000
        }).then(value => {
            console.log(value.data);
        }).catch(reason=>{
            console.log("异常",axios.isCancel(reason),reason)
        })
    }
    btns[1].onclick = function () {
        if(cancelFn)
            cancelFn();
    }
</script>
</html>